package com.ljf.auto;

import com.auth0.jwt.JWT;
import com.ljf.token.TokenTemplate;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;

@AutoConfiguration
@EnableConfigurationProperties(value = {TokenProperties.class})//启用属性的批量绑定
@ConditionalOnClass({JWT.class})
@ConditionalOnProperty(prefix = "token", name = "enabled", matchIfMissing = true)
public class TokenAutoConfigure {

    @Bean
    @ConditionalOnMissingBean(value = {TokenTemplate.class})//如果容器中没有tokenTemplate
    public TokenTemplate tokenTemplate(TokenProperties tokenProperties) {
        TokenTemplate tokenTemplate = new TokenTemplate(tokenProperties);
        return tokenTemplate;
    }
}
